package com.itheima.Controller;

import com.itheima.Service.StudentService;
import com.itheima.entity.EmpParam;
import com.itheima.entity.PageBean;
import com.itheima.entity.Result;
import com.itheima.entity.Student;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
public class StudentController {
    @Autowired
    private StudentService studentService;

    //学员列表查询
    @GetMapping("/students")
    public Result getListStudents(EmpParam empParam) {
        log.info("测试接收数据结果{}", empParam);
        //调用Service层
        PageBean pageBean = studentService.getListStudent(empParam);
        return Result.success(pageBean);
    }

    //学院批量删除
    @DeleteMapping("/students/{ids}")
    public Result deleteStudents(@PathVariable List<Integer> ids) {
        log.info("测试接收数据结果{}", ids);
        //调用Service层
        studentService.deleteStudents(ids);
        return Result.success();
    }

    //添加学员
    @PostMapping("/students")
    public Result addStudent(@RequestBody Student student) {
        log.info("检测接收数据的完整性{}", student);
        //调用Service层
        studentService.addstudent(student);
        return Result.success();
    }

    //根据id查询学员信息
    @GetMapping("/students/{id}")
    public Result getStudentById(@PathVariable Integer id) {
        //调用Service层
        Student student = studentService.getStudentById(id);
        return Result.success(student);
    }

    //修改学员信息
    @PutMapping("/students")
    public Result updateStudent(@RequestBody Student student) {
        //调用Service层
        studentService.updateStudent(student);
        return Result.success();
    }
    //违纪处理操作（修改学员数据）
    @PutMapping("/students/violation/{id}/{score}")
    public Result violation(@PathVariable Integer id, @PathVariable Integer score) {
        //调用Service层
        studentService.violation(id,score);
        return Result.success();
    }
}
